/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "virtual_machine_inst")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "VirtualMachineInst.findAll", query = "SELECT v FROM VirtualMachineInst v"),
    @NamedQuery(name = "VirtualMachineInst.findById", query = "SELECT v FROM VirtualMachineInst v WHERE v.id = :id"),
    @NamedQuery(name = "VirtualMachineInst.findByIdHost", query = "SELECT v FROM VirtualMachineInst v WHERE v.idHost = :idHost"),
    @NamedQuery(name = "VirtualMachineInst.findByCurrentState", query = "SELECT v FROM VirtualMachineInst v WHERE v.currentState = :currentState"),
    @NamedQuery(name = "VirtualMachineInst.findByIdCloudSupplier", query = "SELECT v FROM VirtualMachineInst v WHERE v.idCloudSupplier = :idCloudSupplier")})
public class VirtualMachineInst implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private String id;
    @Column(name = "Id_Host")
    private String idHost;
    @Column(name = "CurrentState")
    private String currentState;
    @Column(name = "Id_Cloud_Supplier")
    private String idCloudSupplier;
    @OneToMany(mappedBy = "idVMInstance")
    private Collection<ServiceInstance> serviceInstanceCollection;
    @JoinColumn(name = "Id_VMConf", referencedColumnName = "ID")
    @ManyToOne
    private VirtualMachineConf idVMConf;
    @JoinColumn(name = "ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Component component;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "virtualMachineInst")
    private Collection<VirtualMachineResources> virtualMachineResourcesCollection;

    public VirtualMachineInst() {
    }

    public VirtualMachineInst(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getIdHost() {
        return idHost;
    }

    public void setIdHost(String idHost) {
        this.idHost = idHost;
    }

    public String getCurrentState() {
        return currentState;
    }

    public void setCurrentState(String currentState) {
        this.currentState = currentState;
    }

    public String getIdCloudSupplier() {
        return idCloudSupplier;
    }

    public void setIdCloudSupplier(String idCloudSupplier) {
        this.idCloudSupplier = idCloudSupplier;
    }

    @XmlTransient
    public Collection<ServiceInstance> getServiceInstanceCollection() {
        return serviceInstanceCollection;
    }

    public void setServiceInstanceCollection(Collection<ServiceInstance> serviceInstanceCollection) {
        this.serviceInstanceCollection = serviceInstanceCollection;
    }

    public VirtualMachineConf getIdVMConf() {
        return idVMConf;
    }

    public void setIdVMConf(VirtualMachineConf idVMConf) {
        this.idVMConf = idVMConf;
    }

    public Component getComponent() {
        return component;
    }

    public void setComponent(Component component) {
        this.component = component;
    }

    @XmlTransient
    public Collection<VirtualMachineResources> getVirtualMachineResourcesCollection() {
        return virtualMachineResourcesCollection;
    }

    public void setVirtualMachineResourcesCollection(Collection<VirtualMachineResources> virtualMachineResourcesCollection) {
        this.virtualMachineResourcesCollection = virtualMachineResourcesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof VirtualMachineInst)) {
            return false;
        }
        VirtualMachineInst other = (VirtualMachineInst) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.VirtualMachineInst[ id=" + id + " ]";
    }
    
}
